<?php
/**
 * 车商模块逻辑层
 */
namespace AuctionBack\Logic;
use AuctionBack\Model\CarDealerModel;
use AuctionCore\AntNest\UserCenter;
use AuctionCore\CarDealer\Dealer;

class CarDealerLogic {

    Protected $autoCheckFields = false;
    
    /**
     * 车商id
     */
    private $dealer_id;

    /**
     * 构造,初始化"车商id"
     */
    public function __construct($dealer_id)
    {
        $this->dealer_id = $dealer_id;
    }

    /**查询车商的ID
     *
     * @param $info id、 车商名、车商手机号
     * return int
     */
    public static function getDealerIdByDealerInfo($info)
    {   
        $map = [];
        $dealer = D('CarDealer','Model');
        if (is_numeric($info)) {
            //$map['contact_mobile'] = ['eq',$info];
            $uc = new UserCenter();
            $data = $uc->info_bymobile($info,2);
            $dealer = new Dealer();
            $dealer_id = $dealer->uid_to_dealerid($data['account_id']);
            return $dealer_id;
        }
        if (!is_numeric($info)) {
            $map['contact_person'] = ['eq',$info];
            $id = $dealer->where($map)->getField("dealer_id");
            return $id;
        }
    }

    public static function getDealerInfoByMap($map)
    {
        $dealer = D('CarDealer','Model');
        return $dealerInfo =  $dealer->where($map)->find();
    }

    public function detail()
    {
        return D('CarDealer','Model')->where("dealer_id='{$this->dealer_id}'")->find();
    }

}